import axios from 'axios'

const state = {
    username:'alice'
}

const getters = {
    reverseUsername(state){
        return state.username.split('').reverse().join('')
    }
}

const mutations = {
    setUsername(state,newValue){
        state.username = newValue
    }
}

const actions = {
    async setUsernameAsync(context,uid){
        const {data:res} = await axios.get(`http://tangxiaoyang.vip:8881/ums/user/findById?id=${uid}`)
        if(res.status === 1){
            context.commit('setUsername',res.data.name)
        }
    }
}

export default {
    state,
    getters,
    mutations,
    actions
}